#include "XmlInfoAgence.hpp"

#include <QtCore/QStringList>

#include <QtCore/QDebug>

#include <iostream>

#include "Utils/Callback.hpp"

using namespace std;

XmlInfoAgence XmlInfoAgence::creeInstance( const QString& nomFichier,
					   const QHash< QString,
							QString >* infos )
{
   QStringList elementsRecuperables;
   elementsRecuperables << "id" << "name" << "days" << "level" << "score" << "reputation"
			<< "portails" << "cities" << "monsters" << "maxMonsters"
			<< "scared" << "devoured" << "contractsA" << "failedA"
                        << "contractsB" << "failedB" << "contractsC" << "failedC"
                        << "contractsD" << "failedD" << "contractsE" << "failedE"
			<< "syndicate" << "syndicateId" << "gold" << "mails"
			<< "fartBox" << "fartTotal";
  QStringList elementsRecuperes;
  
  foreach ( QString tmp, elementsRecuperables )
    {
      elementsRecuperes << (*infos)[ tmp ];
    }

  XmlInfoAgence retour;

  retour . setNomFichier( nomFichier );

  // Récupération des infos obligatoires :
  if ( ! appelleSetUnsigned( elementsRecuperes[ 0 ],
                             &XmlInfoIdentifiant::setIdentification,
                             static_cast< XmlInfoIdentifiant* >( &retour ),
                             elementsRecuperables[ 0 ] ) )
    return XmlInfoAgence();
  
  retour . setNom( elementsRecuperes[ 1 ] );

  if ( ! appelleSetUnsigned( elementsRecuperes[ 2 ], &XmlInfoAgence::setNbrJours,
			     &retour, elementsRecuperables[ 2 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 3 ], &XmlInfoAgence::setNiveau,
			     &retour, elementsRecuperables[ 3 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 4 ], &XmlInfoAgence::setScore,
			     &retour, elementsRecuperables[ 4 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 5 ], &XmlInfoAgence::setReputation,
			     &retour, elementsRecuperables[ 5 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 6 ], &XmlInfoAgence::setNbrPortails,
			     &retour, elementsRecuperables[ 6 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 7 ], &XmlInfoAgence::setNbrVilles,
			     &retour, elementsRecuperables[ 7 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 8 ], &XmlInfoAgence::setNbrMonstres,
			     &retour, elementsRecuperables[ 8 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 9 ], &XmlInfoAgence::setNbrMaxMonstres,
			     &retour, elementsRecuperables[ 9 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 10 ], &XmlInfoAgence::setNbrEffrayes,
			     &retour, elementsRecuperables[ 10 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 11 ], &XmlInfoAgence::setNbrDevores,
			     &retour, elementsRecuperables[ 11 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 12 ], &XmlInfoAgence::setNbrAbordables,
			     &retour, elementsRecuperables[ 12 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 13 ], &XmlInfoAgence::setNbrAbordablesRates,
			     &retour, elementsRecuperables[ 13 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 14 ], &XmlInfoAgence::setNbrNormaux,
			     &retour, elementsRecuperables[ 14 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 15 ], &XmlInfoAgence::setNbrNormauxRates,
			     &retour, elementsRecuperables[ 15 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 16 ], &XmlInfoAgence::setNbrDifficiles,
			     &retour, elementsRecuperables[ 16 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 17 ], &XmlInfoAgence::setNbrDifficilesRates,
			     &retour, elementsRecuperables[ 17 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 18 ], &XmlInfoAgence::setNbrMonstrueux,
			     &retour, elementsRecuperables[ 18 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 19 ], &XmlInfoAgence::setNbrMonstrueuxRates,
			     &retour, elementsRecuperables[ 19 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 20 ], &XmlInfoAgence::setNbrInfernaux,
			     &retour, elementsRecuperables[ 20 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 21 ], &XmlInfoAgence::setNbrInfernauxRates,
			     &retour, elementsRecuperables[ 21 ] ) )
    return XmlInfoAgence();

  retour . setSyndicat( elementsRecuperes[ 22 ] );

  if ( ! appelleSetUnsigned( elementsRecuperes[ 23 ], &XmlInfoAgence::setIdSyndicat,
			     &retour, elementsRecuperables[ 23 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 24 ], &XmlInfoAgence::setNbrMonsterCredits,
			     &retour, elementsRecuperables[ 24 ] ) )
    return XmlInfoAgence();

  if ( ! appelleSetUnsigned( elementsRecuperes[ 25 ], &XmlInfoAgence::setNbrMailsNonLus,
			     &retour, elementsRecuperables[ 25 ] ) )
    return XmlInfoAgence();

  retour . setEmplacementBoite( elementsRecuperes[ 26 ] );

  if ( ! appelleSetDouble( elementsRecuperes[ 27 ], &XmlInfoAgence::setNiveauBoite,
			   &retour, elementsRecuperables[ 27 ] ) )
    return XmlInfoAgence();

  return retour;
}

XmlInfoAgence::XmlInfoAgence( const QString& nomFichier, const unsigned& id,
			      const QString& nom, const unsigned& nbrJours,
			      const unsigned& niveau, const unsigned& score,
			      const unsigned& reputation,
			      const unsigned& nbrPortails,
			      const unsigned& nbrVilles,
			      const unsigned& nbrMonstres,
			      const unsigned& nbrMaxMonstres,
			      const unsigned& nbrEffrayes,
			      const unsigned& nbrDevores,
			      const unsigned& nbrAbordables,
			      const unsigned& nbrAbordablesRates,
			      const unsigned& nbrNormaux,
			      const unsigned& nbrNormauxRates,
			      const unsigned& nbrDifficiles,
			      const unsigned& nbrDifficilesRates,
			      const unsigned& nbrMonstrueux,
			      const unsigned& nbrMonstrueuxRates,
			      const unsigned& nbrInfernaux,
			      const unsigned& nbrInfernauxRates,
			      const unsigned& idSyndicat,
			      const QString& syndicat,
			      const unsigned& nbrMonsterCredits,
			      const unsigned& nbrMailsNonLus,
			      const QString& emplacementBoite,
			      const double& niveauBoite )
  : XmlInfoNom( nomFichier, id, nom ), NbrJours( nbrJours ),
    Niveau( niveau ), Score( score ), Reputation( reputation ),
    NbrPortails( nbrPortails ), NbrVilles( nbrVilles ),
    NbrMonstres( nbrMonstres ), NbrMaxMonstres( nbrMaxMonstres ),
    NbrEffrayes( nbrEffrayes ), NbrDevores( nbrDevores ),
    NbrAbordables( nbrAbordables ), NbrAbordablesRates( nbrAbordablesRates ),
    NbrNormaux( nbrNormaux ), NbrNormauxRates( nbrNormauxRates ),
    NbrDifficiles( nbrDifficiles ), NbrDifficilesRates( nbrDifficilesRates ),
    NbrMonstrueux( nbrMonstrueux ), NbrMonstrueuxRates( nbrMonstrueuxRates ),
    NbrInfernaux( nbrInfernaux ), NbrInfernauxRates( nbrInfernauxRates ),
    IdSyndicat( idSyndicat ), Syndicat( syndicat ),
    NbrMonsterCredits( nbrMonsterCredits ), NbrMailsNonLus( nbrMailsNonLus ),
    EmplacementBoite( emplacementBoite ), NiveauBoite( niveauBoite )
{}

XmlInfoAgence::XmlInfoAgence( const XmlInfoAgence& agence )
  : XmlInfoNom( agence ), NbrJours( agence.nbrJours() ),
    Niveau( agence.niveau() ), Score( agence.score() ),
    Reputation( agence.reputation() ), NbrPortails( agence.nbrPortails() ),
    NbrVilles( agence.nbrVilles() ), NbrMonstres( agence.nbrMonstres() ),
    NbrMaxMonstres( agence.nbrMaxMonstres() ),
    NbrEffrayes( agence.nbrEffrayes() ), NbrDevores( agence.nbrDevores() ),
    NbrAbordables( agence.nbrAbordables() ),
    NbrAbordablesRates( agence.nbrAbordablesRates() ),
    NbrNormaux( agence.nbrNormaux() ),
    NbrNormauxRates( agence.nbrNormauxRates() ),
    NbrDifficiles( agence.nbrDifficiles() ),
    NbrDifficilesRates( agence.nbrDifficilesRates() ),
    NbrMonstrueux( agence.nbrMonstrueux() ),
    NbrMonstrueuxRates( agence.nbrMonstrueuxRates() ),
    NbrInfernaux( agence.nbrInfernaux() ),
    NbrInfernauxRates( agence.nbrInfernauxRates() ),
    IdSyndicat( agence.idSyndicat() ),
    Syndicat( agence.syndicat() ),
    NbrMonsterCredits( agence.nbrMonsterCredits() ),
    NbrMailsNonLus( agence.nbrMailsNonLus() ),
    EmplacementBoite( agence.emplacementBoite() ),
    NiveauBoite( agence.niveauBoite() )
{}

XmlInfoAgence::XmlInfoAgence()
{}

XmlInfoAgence::~XmlInfoAgence()
{}

XmlInfoAgence& XmlInfoAgence::operator=( const XmlInfoAgence& agence )
{
  this -> XmlInfoNom::operator=( agence );
  NbrJours = agence.nbrJours();
  Niveau = agence.niveau();
  Score = agence.score();
  Reputation = agence.reputation();
  NbrPortails = agence.nbrPortails();
  NbrVilles = agence.nbrVilles();
  NbrMonstres = agence.nbrMonstres();
  NbrMaxMonstres = agence.nbrMaxMonstres();
  NbrEffrayes = agence.nbrEffrayes();
  NbrDevores = agence.nbrDevores();
  NbrAbordables = agence.nbrAbordables();
  NbrAbordablesRates = agence.nbrAbordablesRates();
  NbrNormaux = agence.nbrNormaux();
  NbrNormauxRates = agence.nbrNormauxRates();
  NbrDifficiles = agence.nbrDifficiles();
  NbrDifficilesRates = agence.nbrDifficilesRates();
  NbrMonstrueux = agence.nbrMonstrueux();
  NbrMonstrueuxRates = agence.nbrMonstrueuxRates();
  NbrInfernaux = agence.nbrInfernaux();
  NbrInfernauxRates = agence.nbrInfernauxRates();
  IdSyndicat = agence.idSyndicat();
  Syndicat = agence.syndicat();
  NbrMonsterCredits = agence.nbrMonsterCredits();
  NbrMailsNonLus = agence.nbrMailsNonLus();
  EmplacementBoite = agence.emplacementBoite();
  NiveauBoite = agence.niveauBoite();

  return *this;
}

void XmlInfoAgence::afficheInstance() const
{
  qDebug() << QObject::trUtf8( "Agence '%1', n° identification %2" ).arg( nom() ).arg( identification() );
  qDebug() << QObject::trUtf8( "Niveau d'accréditation %1, score %2, réputation %3" ).arg( niveau() ).arg( score() ).arg( reputation() );
  qDebug() << QObject::trUtf8( "Existe depuis %n jour(s)", "", nbrJours() );
  qDebug() << QObject::trUtf8( "%n portail(s)", "", nbrPortails() );
  qDebug() << QObject::trUtf8( "%n ville(s) contrôlée(s)", "", nbrVilles() );
  qDebug() << QObject::trUtf8( "%n/%1 monstre(s)", "", nbrMonstres() ).arg( nbrMaxMonstres() );
  qDebug() << QObject::trUtf8( "Enfant(s) effrayé(s) : %n", "", nbrEffrayes() ) + QObject::trUtf8( ", dévoré(s) : %n", "", nbrDevores() );
  qDebug() << QObject::trUtf8( "Contrat(s) abordable(s) réussi(s) : %n/%1",
			       "", nbrAbordables() ).arg( nbrAbordables() + nbrAbordablesRates() );
  qDebug() << QObject::trUtf8( "Contrat(s) normal(aux) réussi(s) : %n/%1",
			       "", nbrNormaux() ).arg( nbrNormaux() + nbrNormauxRates() );
  qDebug() << QObject::trUtf8( "Contrat(s) difficile(s) réussi(s) : %n/%1",
			       "", nbrDifficiles() ).arg( nbrDifficiles() + nbrDifficilesRates() );
  qDebug() << QObject::trUtf8( "Contrat(s) monstrueux réussi(s) : %n/%1",
			       "", nbrMonstrueux() ).arg( nbrMonstrueux() + nbrMonstrueuxRates() );
  qDebug() << QObject::trUtf8( "Contrat(s) infernal(aux) réussi(s) : %n/%1",
			       "", nbrInfernaux() ).arg( nbrInfernaux() + nbrInfernauxRates() );
  if ( idSyndicat() > 0u )
    qDebug() << QObject::trUtf8( "Syndicat '%1', identification %2." ).arg( syndicat() ).arg( idSyndicat() );
  qDebug() << QObject::trUtf8( "Boîte à pet sur %1, niveau %2 mètres cubes." ).arg( emplacementBoite() ).arg( niveauBoite() );
  qDebug() << QObject::trUtf8( "%n message(s) non-lu(s).", "", nbrMailsNonLus() );
  qDebug() << QObject::trUtf8( "Fortune : %n monstercrédit(s)", "", nbrMonsterCredits() );
}

const unsigned& XmlInfoAgence::nbrJours() const
{
  return NbrJours;
}


void XmlInfoAgence::setNbrJours( const unsigned& nbrJours )
{
  NbrJours = nbrJours;
}


const unsigned& XmlInfoAgence::niveau() const
{
  return Niveau;
}


void XmlInfoAgence::setNiveau( const unsigned& niveau )
{
  Niveau = niveau;
}


const unsigned& XmlInfoAgence::score() const
{
  return Score;
}


void XmlInfoAgence::setScore( const unsigned& score )
{
  Score = score;
}


const unsigned& XmlInfoAgence::reputation() const
{
  return Reputation;
}


void XmlInfoAgence::setReputation( const unsigned& reputation )
{
  Reputation = reputation;
}


const unsigned& XmlInfoAgence::nbrPortails() const
{
  return NbrPortails;
}


void XmlInfoAgence::setNbrPortails( const unsigned& nbrPortails )
{
  NbrPortails = nbrPortails;
}


const unsigned& XmlInfoAgence::nbrVilles() const
{
  return NbrVilles;
}


void XmlInfoAgence::setNbrVilles( const unsigned& nbrVilles )
{
  NbrVilles = nbrVilles;
}


const unsigned& XmlInfoAgence::nbrMonstres() const
{
  return NbrMonstres;
}


void XmlInfoAgence::setNbrMonstres( const unsigned& nbrMonstres )
{
  NbrMonstres = nbrMonstres;
}


const unsigned& XmlInfoAgence::nbrMaxMonstres() const
{
  return NbrMaxMonstres;
}


void XmlInfoAgence::setNbrMaxMonstres( const unsigned& nbrMaxMonstres )
{
  NbrMaxMonstres = nbrMaxMonstres;
}


const unsigned& XmlInfoAgence::nbrEffrayes() const
{
  return NbrEffrayes;
}


void XmlInfoAgence::setNbrEffrayes( const unsigned& nbrEffrayes )
{
  NbrEffrayes = nbrEffrayes;
}


const unsigned& XmlInfoAgence::nbrDevores() const
{
  return NbrDevores;
}


void XmlInfoAgence::setNbrDevores( const unsigned& nbrDevores )
{
  NbrDevores = nbrDevores;
}


const unsigned& XmlInfoAgence::nbrAbordables() const
{
  return NbrAbordables;
}


void XmlInfoAgence::setNbrAbordables( const unsigned& nbrAbordables )
{
  NbrAbordables = nbrAbordables;
}


const unsigned& XmlInfoAgence::nbrAbordablesRates() const
{
  return NbrAbordablesRates;
}


void XmlInfoAgence::setNbrAbordablesRates( const unsigned& nbrAbordablesRates )
{
  NbrAbordablesRates = nbrAbordablesRates;
}


const unsigned& XmlInfoAgence::nbrNormaux() const
{
  return NbrNormaux;
}


void XmlInfoAgence::setNbrNormaux( const unsigned& nbrNormaux )
{
  NbrNormaux = nbrNormaux;
}


const unsigned& XmlInfoAgence::nbrNormauxRates() const
{
  return NbrNormauxRates;
}


void XmlInfoAgence::setNbrNormauxRates( const unsigned& nbrNormauxRates )
{
  NbrNormauxRates = nbrNormauxRates;
}


const unsigned& XmlInfoAgence::nbrDifficiles() const
{
  return NbrDifficiles;
}


void XmlInfoAgence::setNbrDifficiles( const unsigned& nbrDifficiles )
{
  NbrDifficiles = nbrDifficiles;
}


const unsigned& XmlInfoAgence::nbrDifficilesRates() const
{
  return NbrDifficilesRates;
}


void XmlInfoAgence::setNbrDifficilesRates( const unsigned& nbrDifficilesRates )
{
  NbrDifficilesRates = nbrDifficilesRates;
}


const unsigned& XmlInfoAgence::nbrMonstrueux() const
{
  return NbrMonstrueux;
}


void XmlInfoAgence::setNbrMonstrueux( const unsigned& nbrMonstrueux )
{
  NbrMonstrueux = nbrMonstrueux;
}


const unsigned& XmlInfoAgence::nbrMonstrueuxRates() const
{
  return NbrMonstrueuxRates;
}


void XmlInfoAgence::setNbrMonstrueuxRates( const unsigned& nbrMonstrueuxRates )
{
  NbrMonstrueuxRates = nbrMonstrueuxRates;
}


const unsigned& XmlInfoAgence::nbrInfernaux() const
{
  return NbrInfernaux;
}


void XmlInfoAgence::setNbrInfernaux( const unsigned& nbrInfernaux )
{
  NbrInfernaux = nbrInfernaux;
}


const unsigned& XmlInfoAgence::nbrInfernauxRates() const
{
  return NbrInfernauxRates;
}


void XmlInfoAgence::setNbrInfernauxRates( const unsigned& nbrInfernauxRates )
{
  NbrInfernauxRates = nbrInfernauxRates;
}


const unsigned& XmlInfoAgence::idSyndicat() const
{
  return IdSyndicat;
}


void XmlInfoAgence::setIdSyndicat( const unsigned& idSyndicat )
{
  IdSyndicat = idSyndicat;
}


const QString& XmlInfoAgence::syndicat() const
{
  return Syndicat;
}


void XmlInfoAgence::setSyndicat( const QString& syndicat )
{
  Syndicat = syndicat;
}


const unsigned& XmlInfoAgence::nbrMonsterCredits() const
{
  return NbrMonsterCredits;
}


void XmlInfoAgence::setNbrMonsterCredits( const unsigned& nbrMonsterCredits )
{
  NbrMonsterCredits = nbrMonsterCredits;
}


const unsigned& XmlInfoAgence::nbrMailsNonLus() const
{
  return NbrMailsNonLus;
}


void XmlInfoAgence::setNbrMailsNonLus( const unsigned& nbrMailsNonLus )
{
  NbrMailsNonLus = nbrMailsNonLus;
}


const QString& XmlInfoAgence::emplacementBoite() const
{
  return EmplacementBoite;
}


void XmlInfoAgence::setEmplacementBoite( const QString& emplacementBoite )
{
  EmplacementBoite = emplacementBoite;
}


const double& XmlInfoAgence::niveauBoite() const
{
  return NiveauBoite;
}


void XmlInfoAgence::setNiveauBoite( const double& niveauBoite )
{
  NiveauBoite = niveauBoite;
}
